#ifndef A8_NETBASE_HPP
#define A8_NETBASE_HPP

#include <string>
#include <errno.h>
#include <stdio.h>
#include <a8/delegate.hpp>
#include <a8/thread.hpp>
#include <a8/sync.hpp>
#include <a8/list.hpp>
#include <a8/sysutils.hpp>

#ifdef WIN32   
#include <WinSock2.h>
typedef int socklen_t;
#endif   
#if defined(__linux__) || defined(__FREEBSD__) || defined(__APPLE__)
typedef int SOCKET;   
#define SOCKET_ERROR (-1)   
#define INVALID_SOCKET (-1)
#define closesocket(h) close(h)
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <strings.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <unistd.h>
#include <sys/ioctl.h>
#endif   
#if defined(__FREEBSD__) || defined(__APPLE__)
#include <sys/event.h>
#endif
#if defined(__linux__)
#include <sys/epoll.h>
#endif

#define INVALID_SOCKET_HANDLE (0)

const unsigned short SOCKET_TIMEOUT = 60;

const unsigned short MAX_RECV_BUFFERSIZE = 1024 * 8;

struct SendQueueNode
{
	char* mBuff;
	unsigned int mBuffLen;
	unsigned int mSentBytes;
	SendQueueNode *mNext;
};

#ifdef WIN32
	const unsigned int DISCONNECT_FLAG  = 0xFFFFFFFE;
	const unsigned short MAX_IOCP_BUF_SIZE = MAX_RECV_BUFFERSIZE;

	enum IOCP_OPCODE
		{
			IOCP_RECV,
			IOCP_SEND
		};

	struct IocpOverLapped
	{
		unsigned short mSocketHandle;
		WSABUF mWsaBuf;
		OVERLAPPED mOverLapped;
		IOCP_OPCODE mOpCode;
		char mBuffer[MAX_IOCP_BUF_SIZE];
	};

#endif

#endif
